<?php
/**
 * @filename ProjectController.php 
 * @encoding UTF-8 
 * @author KangShuAn
 * @datetime 2009-12-19 16:46:15
 * @version 1.0
 * @Description 项目，可以将中行，分行，支行指定项目
 */
class ProjectController extends FrontController
{
    /**
     * 项目首页
     * 只有1,2，3级网点可以访问项目
     */
    public function actionIndex()
    {
        $project_id = $this->get('project_id', 0);
        $project = new Project();
        $network = new NetWork();
        $netquestion = new NetworkQuestion();

        $project_list = $project_ids = $network_ids =array();
        if($this->auth_grade == 1) {//如果是总行,得到下级网点,分行、支行
            $network_list = $network->findAll("bank_id={$this->bank_id}");  
        } else{
            $network_list = $network->getAllNext($this->network_id, $this->auth_grade);
        }
        //网点问卷
        $network_ids[0] = $this->network_id;
        foreach ($network_list as $key => $val) {
            $network_ids[] = $val['network_id'];
        }
		
        $netquestion_list = $netquestion->findAll('network_id in (' . join(',', $network_ids) .') and status='.NetworkQuestion::NETWORK_QUESTION_NORMAL);
        foreach ($netquestion_list as $key => $val) {
            $project_ids[$val['project_id']] = $val['project_id'];
        }

        if (empty($project_ids)) {
                $this->smarty->display('error.tpl');exit;
        }
        //得到下级网点项目所有,运行中的
        $project_list = $project->findAll('project_id in ('.join(',',$project_ids).') and status='.Project::PROJECT_RUNNING);
        
        if (!empty($project_list)) {
            $result = array();
            foreach ($project_list as $key => $val) {
                $result[$val['project_id']] = $val;
            }
            unset($project_list);
            $info = isset($result[$project_id]) ? $result[$project_id] : reset($result);
            $project_id = $project_id ? $project_id : $info['project_id'];
        }

        $this->smarty->assign('info', $info);
        $this->smarty->assign('project_id', $project_id);
        $this->smarty->assign('projectlist', $result);
        $this->smarty->display('project/index.tpl');
    }

}
